﻿/*
 * DisplayOrder
 * 
 * initial implementation : 20.10.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Collections;
using System.Collections.Generic;
using Petra.Gis.RenderingServices.PlanarBase.Support;


namespace Petra.Gis.RenderingServices.PlanarBase 
{

  /// <summary>
  /// represents flat (non hierachic) list of renderable legend nodes 
  /// and defines their map display order.
  /// Smaller index in <c>DisplayOrder</c> mean that legend entry is rendered more on top on map
  /// </summary>
  public class DisplayOrder : ChildItemsList<RenderableLegendNodeBase>
  {

    private MapLegend _legend;
    private bool _isReadOnly;

    //public delegate void DisplayOrderChange(object source, int originalPosition, int newPosition);
    //public event DisplayOrderChange OnDisplayOrderChange;



    internal DisplayOrder(MapLegend legend)
      : base()
    {
      _legend = legend;
      _isReadOnly = false;
    }




    internal DisplayOrder(MapLegend legend, IList<RenderableLegendNodeBase> dataStorage)
      : base(dataStorage)
    {
      _legend = legend;
      _isReadOnly = true;
    }




    /// <summary>
    /// display order List is readonly
    /// </summary>
    public override bool IsReadOnly 
    {
      get { return _isReadOnly; }
    }



    public override bool Remove(RenderableLegendNodeBase item)
    {
      //remove from legend first
      if (item.ParentNode.ChildNodes.Remove(item))
        return base.Remove(item);

      else
        return false;
    }




    public override void RemoveAt(int index)
    {
      //remove from legend first
      RenderableLegendNodeBase item = this[index];
      if (item.ParentNode.ChildNodes.Remove(item))
        base.RemoveAt(index);

    }



  }

}
